<template>
  <el-dialog
    title="智能排货"
    :visible="sortvisible"
    @close="close"
    @open="open"
    width="858px"
  >
    <div>该区域属于{{ school }}商圈适合销售一下商品：</div>
    <el-row>
      <el-col :span="5" v-for="item in businessList" :key="item.skuId">
        <div class="item">
          <img :src="item.image" />
          <div class="name">{{ item.skuName }}</div>
        </div>
      </el-col>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="onSubmit">采纳建议</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { businessType, businessTop } from '@/api/device-manager'
export default {
  name: 'SortDailog',
  props: {
    sortvisible: {
      type: Boolean,
      required: true
    }
  },
  data () {
    return {
      businessID: '',
      school: '',
      businessList: []
    }
  },
  methods: {
    close () {
      this.$emit('update:sortvisible', false)
    },
    async open () {
      this.school = await businessType(this.businessID)
      this.businessList = await businessTop(this.businessID)
    },
    onSubmit () {
      this.$emit('suggestList', this.businessList)
      this.close()
      this.$message({ type: 'success', message: '采纳成功' })
    }
  }
}
</script>
<style lang="scss" scoped>
  .el-row {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    .el-col {
      width: 20%;
      margin-bottom: 20px;
      .item {
        width: 134px;
        height: 134px;
        padding-top: 16px;
        background-color: #f6f7fb;
        box-shadow: 0 2px 4px 0 rgb(0 0 0 / 6%);
        border-radius: 4px;
        text-align: center;
        img {
          height: 84px;
        }
      }
    }
  }
</style>
